﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace YTSK.FrmKP
{
    public partial class FrmVouchCode : Form
    {
        public string cCode = "";
        public int idwarehouse = 0;
        public FrmVouchCode()
        {
            InitializeComponent();
            GetWarehouse();
        }

        private void GetWarehouse()
        {
            var result =Report.ReportData.GetReportData("warehouseAuth");
            if (result.result != 1) { return; }
            var data = result.GetListDic("data");
            this.cbWarehouse.Items.Clear();
            var dt = new DataTable();
            dt.Columns.Add("key");
            dt.Columns.Add("value");
            for (int i = 0; i < data.Count; i++)
            {
                var t = data[i];
                var dtr = dt.NewRow();
                dtr["key"] = t["ID"].ObjToInt();
                dtr["value"] = t["cWhName"].ObjToString();
                dt.Rows.Add(dtr);
            }
            this.cbWarehouse.DataSource = dt;
            this.cbWarehouse.DisplayMember = "value";
            this.cbWarehouse.ValueMember = "key";
        }

        private void btLogin_Click(object sender, EventArgs e)
        {
            cCode = this.textBox1.Text.Trim();
            if (cCode.Length == 0)
            { MessageBox.Show("请输入号码，如3812399"); return; }
            idwarehouse = this.cbWarehouse.SelectedValue.ObjToInt();
            this.Hide();
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            cCode = "";
            this.Hide();
        }


        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            { cCode = this.textBox1.Text; idwarehouse = this.cbWarehouse.SelectedValue.ObjToInt(); this.Hide(); }
        }
    }
}
